/**
 * 
 */
package com.n9.qq.util;

/**
 * @author N9
 *
 */
public abstract class ThreadUtils {
	/**
	 * 当前线程等待 millisecond 毫秒
	 * @param millisecond
	 */
	public static void sleep(long millisecond) {
		try {
			Thread.sleep(millisecond);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 当前线程等待<br/>
	 * 唤醒条件:<br/>
	 * <ul>
	 * 		<li>等到超时时间结束,系统自动唤醒</li>
	 * 		<li>其他线程通过lock唤醒</li>
	 * </ul>
	 * @param lock
	 * @param timeout
	 */
	public static void wait(Object lock, long timeout) {
		synchronized (lock) {
			try {
				lock.wait(timeout);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 
	 * 当前线程等待<br/>
	 * 唤醒条件:<br/>
	 * <ul>
	 * 		<li>其他线程通过lock唤醒</li>
	 * </ul>
	 * @param lock
	 */
	public static void wait(Object lock) {
		synchronized (lock) {
			try {
				lock.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	
	/**
	 * 
	 * 唤醒附件在lock上的所有线程
	 * 
	 * @param lock
	 */
	public static void notifyAll(Object lock) {
		synchronized (lock) {
			lock.notifyAll();
		}
	}
	
}
